package cn.tedu.bonfire.front.content.controller;

import cn.tedu.bonfire.common.pojo.authentication.CurrentPrincipal;
import cn.tedu.bonfire.common.web.JsonResult;
import cn.tedu.bonfire.front.content.pojo.vo.InformVO;
import cn.tedu.bonfire.front.content.service.IInformService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/inform")
@Validated
@Api(tags = "6.通知模块")
public class InformController {

    @Autowired
    IInformService informService;

    @GetMapping("{type}/newInform-count")
    @ApiOperation("查询新通知条数")
    @ApiOperationSupport(order = 100)
    public JsonResult newInformsCount(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,
                                      @PathVariable Integer type) {
        Long userId = currentPrincipal.getId();
        int number = informService.countNewInforms(userId,type);
        return JsonResult.ok(number);
    }

    @PostMapping("{type}/update")
    @ApiOperation("更新通知")
    @ApiOperationSupport(order = 200)
    public JsonResult updateNewInform(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,
                                      @PathVariable Integer type) {
        Long userId = currentPrincipal.getId();
        informService.updateNewInforms(userId,type);
        return JsonResult.ok();
    }

    @GetMapping("{type}/All")
    @ApiOperation("获取所有通知")
    @ApiOperationSupport(order = 400)
    public JsonResult listAllInform(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,
                                    @PathVariable Integer type) {
        Long userId = currentPrincipal.getId();
        List<InformVO> informs = informService.listAllInforms(userId,type);
        return JsonResult.ok(informs);
    }
}
